package com.eastfair.datasync.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.eastfair.core.httpClient.PostHttpClient;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
public class RomaUtil {

    public static void executeHttp(String url, String name, List dataList, String appId, String appKey) {
        url = url.replaceAll("/name/", "/" + name + "/");
        log.info("RomaUtil url is {}", url);
        //header头
        Map<String, String> headerMap = new HashMap<>();
        headerMap.put("X-HW-ID", appId);
        headerMap.put("X-HW-APPKEY", appKey);
        JSONObject params = new JSONObject();
        params.put("data", dataList);
        log.info("executeHttp send is execute  url:{} , params: {} , header : {}", url, JSONObject.toJSONString(params, new SerializerFeature[]{SerializerFeature.WriteMapNullValue}), JSON.toJSONString(headerMap));
        String result = PostHttpClient.postForm(url, params, headerMap);
        log.info("result is {}", result);
    }


}
